package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类与属性管理控制层
 */
@RestController
@RequestMapping("/admin/product/")
public class ManageController {
    @Autowired
    private ManageService manageService;

    /**
     * 查询全部一级分类的信息
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1List(){
        List<BaseCategory1> category1List = manageService.getCategory1List();
        return Result.ok(category1List);
    }

    /**
     * 根据一级分类的id查询二级分类的信息
     * @param id
     * @return
     */
    @GetMapping("/getCategory2/{id}")
    public Result getCategory2(@PathVariable(value = "id")Long id){
        List<BaseCategory2> category2List = manageService.getCategory2List(id);
        return Result.ok(category2List);
    }

    /**
     * 根据二级分类的id查询三级分类的信息
     * @param id
     * @return
     */
    @GetMapping("/getCategory3/{id}")
    public Result getCategory3(@PathVariable(value = "id")Long id){
        List<BaseCategory3> category3List = manageService.getCategory3List(id);
        return Result.ok(category3List);
    }

    /**
     * 查询1 2 3级分类对应的规格信息列表，若只查询某一个分类下的规格列表则其他分值传0
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getBaseAttrInfoList(@PathVariable(value = "category1Id") Long category1Id,
                                      @PathVariable(value = "category2Id") Long category2Id,
                                      @PathVariable(value = "category3Id") Long category3Id){

        List<BaseAttrInfo> attrInfoList = manageService.getBaseAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoList);
    }

}
